package gameserver.network.game;

import java.nio.ByteBuffer;

import com.my.commons.network.packet.BaseServerPacket;

public abstract class GameServerPacket extends BaseServerPacket
{
	private ByteBuffer buf;
	
	protected GameServerPacket()
	{
		super();
		setOpcode(ServerPacketsOpcodes.getOpcode(getClass()));
	}
	
	private final void writeOP(ByteBuffer buf,int value)
	{
		
	}
	
	private final byte[] toBytes(short s) {
		return new byte[]{(byte)(s & 0x00FF),(byte)((s & 0xFF00)>>8)};
	}

	public final void write(PlayerConnection con)
	{
		write(con, buf);
	}
	
	public final void write(PlayerConnection con, ByteBuffer buf)
	{
		buf.putShort((short) 0);
		writeOP(buf, getOpcode());
		writeImpl(con, buf);
		buf.flip();
		buf.putShort((short) buf.limit());
		ByteBuffer b = buf.slice();
		buf.position(0);
		con.encrypt(b);
	}
	
	protected void writeImpl(PlayerConnection con, ByteBuffer buf)
	{

	}
	
	public ByteBuffer getBuf()
	{
		return buf;
	}

	public void setBuf(ByteBuffer buf)
	{
		this.buf = buf;
	}
}
